package com.cqc.paoclient.ui.login;

import android.support.design.widget.TextInputEditText;
import android.support.v7.widget.Toolbar;
import android.widget.Button;

import com.cqc.paoclient.R;
import com.cqc.paoclient.base.BaseActivity;
import com.cqc.paoclient.event.LoginSuccessEvent;
import com.cqc.paoclient.model.BaseMsgModel;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by cui on 2017/11/25.
 */

public class LoginActivity extends BaseActivity<LoginPresenter> implements LoginContract.View {

    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.tiet_count)
    TextInputEditText tietCount;
    @BindView(R.id.tiet_pwd)
    TextInputEditText tietPwd;
    @BindView(R.id.bt_login)
    Button btLogin;

    @Override
    public int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    public LoginPresenter getmPresenter() {
        return new LoginPresenter();
    }

    @Override
    public void presenterSetView() {
        if (mPresenter != null) {
            mPresenter.setView(this);
        }
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {
    }

    @Override
    public void loginSuccess(BaseMsgModel result) {
        if (result.getSucess() == 1) {
            EventBus.getDefault().post(new LoginSuccessEvent());
        }
        showShort(result.getMessage());
    }

    @Override
    public void loginFail(String error) {
        showShort(error);
    }


    @OnClick(R.id.bt_login)
    public void onClick() {
        String name = tietCount.getText().toString().trim();
        String pwd = tietPwd.getText().toString().trim();
        mPresenter.login(name, pwd);
    }
}
